package com.serviceprovider.business.module.order.valueobjects;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.order.model.OrderAttribute;
import com.serviceprovider.business.module.order.model.OrderAttributeType;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayList;
import java.util.List;

public class OrderAttributeVO {
    private String             list     = "";
    private OrderAttributeType type     = OrderAttributeType.STRING;
    private List<String>       enumList = new ArrayList<String>();
    private Integer            id;
    private boolean            isActive;
    private String             name;

    public OrderAttributeVO() {}

    public OrderAttributeVO(OrderAttribute orderAttribute) {
        this.setActive(orderAttribute.isActive());
        this.setId(orderAttribute.getId());
        this.setName(orderAttribute.getName());
        this.setType(orderAttribute.getType());
        enumList.clear();
        enumList.addAll(orderAttribute.getEnumList());
        setStringList();
    }

    private void setStringList() {
        for (String item : enumList) {
            if (list.length() != 0) {
                list += ";" + item;
            } else {
                list += item;
            }
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public OrderAttributeType getType() {
        return type;
    }

    public void setType(OrderAttributeType type) {
        this.type = type;
    }

    public List<String> getEnumList() {
        return enumList;
    }

    public void setEnumList(List<String> enumList) {
        this.enumList = enumList;
        setStringList();
    }

    public boolean isActive() {
        return isActive;
    }

    public void setActive(boolean active) {
        isActive = active;
    }

    public String getList() {
        return list;
    }

    public void setList(String list) {
        this.list = list;

        String[] result = list.split(";");

        enumList.clear();

        for (String item : result) {
            enumList.add(item);
        }
    }
}



